<%--
  Created by IntelliJ IDEA.
  User: FT
  Date: 2020/9/23
  Time: 17:57
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>修改用户</title>
    <script>
        $(function () {
            var deptId = $("#deptId").val();
            // console.log(deptId)
            $.ajax({
                url: "${pageContext.request.contextPath}/dept/list",
                type: "post",
                data: "",
                dataType: "json",
                success: function (data) {
                    // alert(data)
                    // console.log(data);
                    // console.log(parentList[1].id);
                    // console.log(sonList[1].parentId);
                    var html = "";
                    for (var i = 0; i < data.length; i++) {
                        if (deptId==data[i].id){
                            html += '<option selected value="' + data[i].id + '">' + data[i].name + '</option>';
                        }else
                        html += '<option value="' + data[i].id + '">' + data[i].name + '</option>';
                    }
                    $("#dept").append(html)
                }
            });
            // console.log($("#dept"))
        });
    </script>
    <style>
        .box {
            width: 20%;
            margin: 5% auto;
        }

        label {
            margin-top: 2%;
            margin-left: 10%;
            display: inline-block;
            width: 70px;
        }

        .add {
            margin-left: 10%;
            margin-bottom: 2%;
            width: 60px;
            height: 30px;
        }

        .add:hover {
            background-color: red;
        }
    </style>
</head>
<body>
<jsp:include page="/html/commons/top.jsp"></jsp:include>
<jsp:include page="/html/commons/menu.jsp"></jsp:include>
<div id="right">
    <div class="box">
        <form action="${pageContext.request.contextPath}/user/update" method="post">
            <input type="hidden" name="id" value="${user.id}">
            <input type="hidden" id="deptId" value="${user.deptId}">
            <label>用户名</label>
            <input type="text" name="username" value="${user.username}"> <br><br>
            <label>真实名字</label>
            <input type="text" name="realName" value="${user.realName}"> <br><br>
            <label>年龄</label>
            <input type="text" name="age" value="${user.age}"><br><br>
            <label>部门</label>
            <select name="deptId" id="dept">
                <option value="-1">请选择</option>
            </select><br><br>
            <label>手机号</label>
            <input type="text" name="phone" value="${user.phone}"><br><br>
            <label>邮箱</label>
            <input type="text" name="email" value="${user.email}"><br><br>
            <label>性别</label>
            <c:choose>
                <c:when test="${user.gender==1}">
                    <input type="radio" name="gender" checked value="1">男
                    <input type="radio" name="gender" value="0">女
                    <input type="radio" name="gender" value="2">人妖<br><br>
                </c:when>
                <c:when test="${user.gender==0}">
                    <input type="radio" name="gender" value="1">男
                    <input type="radio" name="gender" checked value="0">女
                    <input type="radio" name="gender" value="2">人妖<br><br>
                </c:when>
                <c:otherwise>
                    <input type="radio" name="gender" value="1">男
                    <input type="radio" name="gender" value="0">女
                    <input type="radio" name="gender" checked value="2">人妖<br><br>
                </c:otherwise>
            </c:choose>
            <input class="add" type="submit" value="修改">
        </form>
    </div>
</div>
</body>
</html>
